<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | Recharge控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\exception\LogicException;
use common\service\TransactionService;
use think\Request;

class RechargeController extends VerifyController
{
    /**
     * @var \common\service\TransactionService
     */
    protected $transactionService;


    public function __construct()
    {
        parent::__construct();
        $this->transactionService = new TransactionService();
    }

    /**
     * 通过银行转账充值
     * @param Request $request
     * @return \think\Response
     */
    public function rechargeByBankTransfer(Request $request)
    {
        try {
            $param = $request->param();
            $resData = $this->transactionService->rechargeByBankTransfer($param['data']);
            return json(success_response('Bank transfer record added successfully.', $resData));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 财务确认充值
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function confirmRecharge(Request $request)
    {
        try {
            $param = $request->param();
            $resData = $this->transactionService->confirmRecharge($param['recharge_id']);
            return json(success_response('Bank transfer record added successfully.', $resData));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 充值记录查询
     * @param Request $request
     * @return \think\Response
     */
    public function selectRechargeList(Request $request)
    {
        $param = $request->param();
        $resData = $this->transactionService->selectRechargeList($param['param'], $request->getModuleCode());
        return json(success_response('OK', $resData));
    }
}
